1741A - Compare T-Shirt Sizes - CodeForces Solution


implementation implementation strings strings

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    a, b = input().split()
    counter_a = {'L':0,'M':0,'X':0,'S':0}
    counter_b = {'L':0,'M':0,'X':0,'S':0}
    for s in a:
        counter_a[s] += 1
    for d in b:
        counter_b[d] += 1
    if counter_a.get('L') == 1 and counter_b.get('L') ==1:
        if counter_a.get('X') > counter_b.get('X'):
            print('>')
        elif counter_a.get('X') < counter_b.get('X'):
            print('<')
        else:
            print('=')
    elif counter_a.get('L') == 1 and counter_b.get('L') !=1 :
        print('>')
    elif counter_b.get('L') == 1 and counter_a.get('L') != 1 :
        print('<')
    elif counter_a.get('M') == 1 and counter_b.get('M') == 1:
        print('=')
    elif counter_a.get('M') == 1 and counter_b.get('M') != 1:
        print('>')
    elif counter_b.get('M') == 1 and counter_a.get('M') != 1:
        print('<')
    else :
        if counter_a.get('X') < counter_b.get('X'):
            print('>')
        elif counter_a.get('X') > counter_b.get('X'):
            print('<')
        else:
            print('=')

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int t;
    cin >> t;
    while(t--)
    {
        string a,b;
        cin >> a >> b;
        if(a==b)
        {
            cout << "=\n";
            continue;
        }
        int la = a.size();
        int lb = b.size();
        if(a[la-1]=='S' && b[lb-1] != 'S')
        {cout << "<\n";
         continue;}
        if(a[la-1]=='L' && b[lb-1] != 'L')
        {cout << ">\n";
         continue;}
         if(b[lb-1]=='S' && a[la-1] != 'S')
        {cout << ">\n";
         continue;}
        if(b[lb-1]=='L' && a[la-1] != 'L')
        {cout << "<\n";
         continue;}

         if(a[la-1]=='M')
         {
            if(b[lb-1]=='S')
            cout << ">\n";
            if(b[lb-1]=='L')
            cout << "<\n";
         }
         if(b[lb-1]=='M')
         {
            if(a[la-1]=='S')
            cout << ">\n";
            if(a[la-1]=='L')
            cout << "<\n";
           
         }
         if(a[la-1]==b[lb-1])
         {
            if(a[la-1]=='L')
            {
                if(a.size()>b.size())
                cout << ">\n";
                else
                cout << "<\n";
                continue;
            }
            if(a[la-1]=='S')
            {
                if(a.size()>b.size())
                cout << "<\n";
                else
                cout << ">\n";
                continue;
            }

         }
    }
}


Comments

Submit
0 Comments
More Questions

281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets